#include <iostream>

using namespace std;
const int N=1e4+10;
const int MOD=1000000007;
int a[N];
int dp[N];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		int maxn=a[i],minn=a[i];
		for(int j=i;j>=1;j--)
		{
			maxn=max(maxn,a[j]);
			minn=min(minn,a[j]);			
			if(i-j==maxn-minn)
			{
				dp[i]=(dp[i]+dp[j-1])%MOD;
			}

		}
	}
	cout<<dp[n]<<endl;
	return 0;
}
